﻿Public Class SearchResourcesForm
    Public idSelected As Integer

    Private Sub SearchResourcesForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        GenericAdministrator.loadGrid(Me.dgvResources, Me.BindingNavigator1, ResourceAdministrator.search)
        Me.setDataGridViewHeaders()
    End Sub

    Private Sub cmdBuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSearch.Click
        Dim id As Integer = -1
        If Me.txtId.Text <> "" Then
            id = CType(Me.txtId.Text, Integer) 
        End If
        GenericAdministrator.loadGrid(Me.dgvResources, Me.BindingNavigator1, ResourceAdministrator.searchDataByFilter(id, Me.txtFirstname.Text, Me.txtSurname.Text, Nothing, Nothing))
    End Sub

    Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click
        Dim id As Integer = Me.dgvResources.CurrentRow.Cells(0).Value
        Dim confirmacion As Integer
        confirmacion = MsgBox("¿Está seguro que desea Eliminar el Recurso seleccionado?", vbYesNo + vbQuestion + vbDefaultButton2, "Salir")
        If confirmacion = vbYes Then
            ResourceAdministrator.deleteById(id)
            GenericAdministrator.loadGrid(Me.dgvResources, Me.BindingNavigator1, ResourceAdministrator.search)
        End If
    End Sub

    Private Sub bdnEditButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bdnEditButton.Click
        idSelected = Me.dgvResources.CurrentRow.Cells(0).Value
        Me.Close()
        Dim resourceForm As New ResourceForm(Me)
        resourceForm.Show()
    End Sub

    Private Sub setDataGridViewHeaders()
        Me.dgvResources.Columns(0).HeaderText = "Legajo"
        Me.dgvResources.Columns(1).HeaderText = "Nombres"
        Me.dgvResources.Columns(2).HeaderText = "Apellido"
        Me.dgvResources.Columns(3).HeaderText = "Email"
        Me.dgvResources.Columns(4).HeaderText = "Fecha Alta"
        Me.dgvResources.Columns(5).HeaderText = "Costo x Hora"
    End Sub

    Private Sub dgvResources_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvResources.CellContentClick

    End Sub

    Private Sub BindingNavigatorMoveNextItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorMoveNextItem.Click

    End Sub
End Class